home *** CD-ROM | disk | FTP | other *** search
/ GameStar 1998 November (Bonus) / GAMESTAR11B.ISO / ENCYC99 / MM / T620273A.DCR / scripts_3_Class PuzzlePiece.ls < prev    next >
Encoding:
Text File  |  1998-07-02  |  4.1 KB  |  190 lines

  1. property objectSprite, objectWidth, objectHeight, solvedLoc, homeLoc, mouseOffset, mouseIsDown, mouseIn, pieceIsSolved, sendsEvent, puzzleGod, cursorGod, infoBox, pieceIn, pieceDropped, solvedLocs, rightMember, leftMember, pieceType, snappy, boardList
  2.  
  3. on mouseEvent me, xEvent, xLoc
  4.   if pieceIsSolved then
  5.     case xEvent of
  6.       #mouseEnter:
  7.         pointCursor(cursorGod)
  8.       #mouseLeave:
  9.         plainCursor(cursorGod)
  10.       #mouseDown:
  11.         newActivePiece(puzzleGod, me)
  12.       #mouseGone:
  13.         plainCursor(cursorGod)
  14.     end case
  15.   else
  16.     case xEvent of
  17.       #mouseEnter:
  18.         if pieceDropped then
  19.           pointCursor(cursorGod)
  20.         end if
  21.       #mouseDown:
  22.         set pieceDropped to 0
  23.         grabCursor(cursorGod)
  24.         set mouseIsDown to 1
  25.         set mouseOffset to xLoc - the loc of sprite objectSprite
  26.         newActivePiece(puzzleGod, me)
  27.       #mouseDrag:
  28.         movePiece(me, xLoc - mouseOffset)
  29.         set mouseIsDown to 1
  30.       #mouseUp:
  31.         pointCursor(cursorGod)
  32.         dropPiece(me, xLoc - mouseOffset)
  33.         set mouseIsDown to 0
  34.       #mouseGone:
  35.         plainCursor(cursorGod)
  36.         set mouseIsDown to 0
  37.         if not pieceDropped then
  38.           dropPiece(me, xLoc - mouseOffset)
  39.         end if
  40.     end case
  41.   end if
  42. end
  43.  
  44. on areYouThere me, xLoc
  45.   set returnThis to inside(xLoc, the rect of sprite objectSprite)
  46.   return returnThis
  47. end
  48.  
  49. on highlight me
  50.   if not pieceIsSolved then
  51.     set the blend of sprite objectSprite to 100
  52.   end if
  53.   catchEvent(infoBox, sendsEvent)
  54. end
  55.  
  56. on unHighlight me
  57.   if not pieceIsSolved then
  58.     set the blend of sprite objectSprite to 60
  59.   end if
  60. end
  61.  
  62. on rightView me
  63.   set the member of sprite objectSprite to rightMember
  64.   updateStage()
  65. end
  66.  
  67. on leftView me
  68.   set the member of sprite objectSprite to leftMember
  69.   updateStage()
  70. end
  71.  
  72. on getType me
  73.   return pieceType
  74. end
  75.  
  76. on getSprite me
  77.   return objectSprite
  78. end
  79.  
  80. on new me, xSprite, xType, xSolved, xBoardList
  81.   set objectSprite to xSprite
  82.   set objectWidth to the width of sprite objectSprite
  83.   set objectHeight to the height of sprite objectSprite
  84.   set homeLoc to the loc of sprite objectSprite
  85.   set solvedLocs to xSolved
  86.   set snappy to point(50, 10)
  87.   set boardList to xBoardList
  88.   set pieceType to xType
  89.   set leftMember to member (string(pieceType) && "left")
  90.   set rightMember to member (string(pieceType) && "right")
  91.   set pieceIsSolved to 0
  92.   set pieceIn to 0
  93.   set mouseIn to 0
  94.   puppetSprite(objectSprite, 1)
  95.   set pieceDropped to 1
  96.   return me
  97. end
  98.  
  99. on linkUp me, xPuzzleGod, xInfoBox
  100.   set puzzleGod to xPuzzleGod
  101.   set infoBox to xInfoBox
  102.   set sendsEvent to addThing(infoBox, me)
  103.   unsolved(me)
  104. end
  105.  
  106. on subscribe me, xCursor
  107.   if cursorGod = 0 then
  108.     nothing()
  109.   else
  110.     unsubscribe(cursorGod, me)
  111.   end if
  112.   set cursorGod to xCursor
  113.   subscribe(cursorGod, me)
  114. end
  115.  
  116. on unsubscribe me
  117.   if cursorGod = 0 then
  118.     nothing()
  119.   else
  120.     unsubscribe(cursorGod, me)
  121.   end if
  122. end
  123.  
  124. on destroy me
  125.   unsubscribe(me)
  126.   puppetSprite(objectSprite, 0)
  127.   set me to 0
  128. end
  129.  
  130. on movePiece me, xLoc
  131.   set the loc of sprite objectSprite to xLoc
  132.   if inside(xLoc, the rightRect of boardList) then
  133.     leftView(me)
  134.   else
  135.     if inside(xLoc, the leftRect of boardList) then
  136.       rightView(me)
  137.     end if
  138.   end if
  139. end
  140.  
  141. on dropPiece me, xLoc
  142.   set pieceDropped to 1
  143.   set newLoc to xLoc
  144.   set itsIn to 0
  145.   repeat with i in solvedLocs
  146.     if inside(newLoc, rect(i - snappy, i + snappy)) then
  147.       set itsIn to 1
  148.       set solvedLoc to i
  149.       deleteOne(solvedLocs, i)
  150.       exit repeat
  151.     end if
  152.   end repeat
  153.   if itsIn then
  154.     set newPieceIn to 1
  155.     set newLoc to solvedLoc
  156.     solved(me)
  157.   else
  158.     unsolved(me)
  159.     if newLoc <> homeLoc then
  160.       wrongSound(puzzleGod)
  161.     end if
  162.     set newPieceIn to 0
  163.     set newLoc to homeLoc
  164.   end if
  165.   movePiece(me, newLoc)
  166.   updateStage()
  167.   if newPieceIn <> pieceIn then
  168.     set pieceIn to newPieceIn
  169.     if pieceIn then
  170.       pieceAdded(puzzleGod)
  171.     else
  172.       pieceRemoved(puzzleGod)
  173.     end if
  174.   end if
  175. end
  176.  
  177. on solved me
  178.   if not pieceIsSolved then
  179.     pieceSolved(puzzleGod)
  180.     set pieceIsSolved to 1
  181.   end if
  182. end
  183.  
  184. on unsolved me
  185.   if pieceIsSolved then
  186.     pieceUnsolved(puzzleGod)
  187.     set pieceIsSolved to 0
  188.   end if
  189. end
  190.